package org.iteam.xlz.manager.action.product;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.iteam.web.struts.action.AbstractModuleAction;
import org.iteam.web.struts.action.RestAction;
import org.iteam.xlz.core.entity.product.ProductTags;
import org.iteam.xlz.core.service.product.ProductTagsService;

@SuppressWarnings("unchecked")
@Results({@Result(name="INDEX",type="freemarker",location="/WEB-INF/content/product/sale/tag.html")})
public class ProductTagsAction extends AbstractModuleAction<ProductTags> implements RestAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3149746946102714968L;
	
	@Override
	public ProductTags getModel() {
		if(null==model){
			model=new ProductTags();
		}
		return model;
	}
	@Override
	@Actions({@Action("/product/sale/tags/index")})
	public String index() throws Exception {
		array = ProductTagsService.getInstance().getProductTags(model.getPid());
		super._id=model.getPid();
		return INDEX;
	}

	@Override
	@Action("/query")
	public String query() {	
		return null;
	}

	@Override
	public String show() {
		return null;
	}

	@Override
	@Actions({@Action("/product/sale/tags/create")})
	public String create() {
		if(StringUtils.isBlank(model.getTag_text())){
			map.put("state",false);
			map.put("info","请输入标签内容");
		}else{
			String info=ProductTagsService.getInstance().create(model);
			map.put("state",null!=info);
			map.put("info",info);
		}
		return MAP;
	}

	@Override
	@Actions({@Action("/product/sale/tags/update")})
	public String update() {
		if(StringUtils.isBlank(model.getTag_text())){
			map.put("state",false);
			map.put("info","请输入标签内容");
		}else{
			map.put("state",ProductTagsService.getInstance().update(model));
		}
		return MAP;
	}

	@Override
	@Actions({@Action("/product/sale/tags/delete")})
	public String delete() {
		map.put("state",ProductTagsService.getInstance().deleteProductTags(model));
		return MAP;
	}

	@Override
	public String destroy() {
		return null;
	}

	@Override
	@Action("/edit")
	public String edit() throws Exception {
		return null;
	}

	@Override
	@Action("/new")
	public String editNew() throws Exception {
		return null;
	}
}
